function getOriginType(o) {
    return Object.prototype.toString.call(o);
}
function type(o) {
    return getOriginType(o).slice(8, -1).toLowerCase();
}

const is = {
    reg: {
        url: /^(http|https|ftp):\/\/[\w\-]+(\.[\w\-]+)*([\w\-\.,@?^=%&:/~\+#]*[\w\-\@?^=%&/~\+#])?$/i,
        domain: /^[a-zA-Z0-9_-]+(\.[a-zA-Z0-9_-]+)+$/,
        email: /^[a-zA-Z0-9_-]+@[a-zA-Z0-9_-]+(\.[a-zA-Z0-9_-]+)+$/,
        phone: /^1[3456789]\d{9}$/,
        id_card: /(^\d{15}$)|(^\d{18}$)|(^\d{17}(\d|X|x)$)/,
        ip: /^((2[0-4]\d|25[0-5]|[01]?\d\d?)\.){3}(2[0-4]\d|25[0-5]|[01]?\d\d?)$/,
    },
    url(v) {
        return this.reg.url.test(v);
    },

    type,
    getOriginType,

    string: (o) => type(o) === 'string',
    number: (o) => type(o) === 'number',
    object: (o) => type(o) === 'object',
    array: (o) => Array.isArray(o),

    function: (o) => type(o) === 'function',
    promise: (o) => type(o) === 'promise',
    set: (o) => type(o) === 'set',
    map: (o) => type(o) === 'map',
    symbol: (o) => type(o) === 'symbol',
    undefined: (o) => type(o) === 'undefined',
    null: (o) => type(o) === 'null',
    nan: (o) => Number.isNaN(o),
    non: (o) => is.undefined(o) || is.null(o),

    setter: (o) => is.object(o) || is.array(o) || is.function(o),

    len: (o) => o?.length > 0,
    validObject: (o) => Boolean(o) && is.object(o),
    validNumber: (o) => !is.nan(o) && is.number(o),
};

export { is };
